package com.ebupt.migu.music.api.controller;

import com.ebupt.migu.music.api.entity.MemberPopResponse;

import com.ebupt.migu.music.api.entity.StrategyInfoBean;
import com.ebupt.migu.music.api.service.MemberPopService;
import com.ebupt.migu.music.common.auth.AuthBaseUtils;
import com.ebupt.migu.music.common.entity.ResultObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/memberPop")
public class MemberPopController {

    //
    @Autowired
    private MemberPopService memberPopService;
    @Autowired
    private HttpServletRequest request;


    @PostMapping("/vipPopUp")
    public MemberPopResponse vipPopUp(String user_id,@RequestParam("type") String type) {
        log.debug("会员弹窗登录访问，访问参数：{}", user_id,type);
        return memberPopService.vipPopUp(user_id,type);
    }




    @PostMapping("/insertVipPopUp")
    public ResultObject insertVipPopUp(@ModelAttribute StrategyInfoBean strategyInfo) {
        // 获取用户信息和业务参数
        Map<String, Object> paramMap = AuthBaseUtils.authBaseInfo(request);
        strategyInfo.setCreatorId(paramMap.get("creatorId").toString());
        strategyInfo.setCreatorName(paramMap.get("creatorName").toString());
        strategyInfo.setCreatorPhone(paramMap.get("creatorPhone").toString());
        strategyInfo.setCreatorEmail(paramMap.get("creatorEmail").toString());
        strategyInfo.setCreatorDepartment(paramMap.get("creatorDepartment").toString());
        return memberPopService.addStrategy(strategyInfo);
    }




    @PostMapping("/updateVipPopUp")
    public ResultObject updateVipPopUp(@ModelAttribute StrategyInfoBean strategyInfo) {
        // 获取用户信息和业务参数
        Map<String, Object> paramMap = AuthBaseUtils.authBaseInfo(request);
        strategyInfo.setCreatorId(paramMap.get("creatorId").toString());
        strategyInfo.setCreatorName(paramMap.get("creatorName").toString());
        strategyInfo.setCreatorPhone(paramMap.get("creatorPhone").toString());
        strategyInfo.setCreatorEmail(paramMap.get("creatorEmail").toString());
        strategyInfo.setCreatorDepartment(paramMap.get("creatorDepartment").toString());
        return memberPopService.addStrategy(strategyInfo);
    }
}
